﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ylh.BLL;
using ExtAspNet;

using System.Data;

/// <summary>
/// 系统中一些必要的全局变量
/// 例如权限,当前登录人的部门信息等
/// </summary>
public class PageBase : Page
{
    protected string DbConnectionStr
    {
        get
        {
            string DbConnection = string.Empty;
            if (Session["DbConnectionStr"] != null)
            {
                DbConnection = Session["DbConnectionStr"].ToString();
            }
            else
            {
                //获取数据库中的链接字符串
                Ylh.BLL.SmDbBLL dbbll = new SmDbBLL();
                Session["DbConnectionStr"] = DbConnection = dbbll.GetConnStr();
            }

            return DbConnection;
        }
    }

    /// <summary>
    /// 当前登录用户的ID
    /// </summary>
    protected decimal StaffID
    {
        get
        {
            return Convert.ToDecimal(Session["StaffID"].ToString());
        }
    }

    /// <summary>
    /// 当前登录用户的所属部门编号
    /// </summary>
    protected decimal DepartmentID
    {
        get
        {

            if (Session["DepartmentID"] == null || string.IsNullOrEmpty(Session["DepartmentID"].ToString()))
            {
                return -1;
            }

            return Convert.ToDecimal(Session["DepartmentID"].ToString());
        }
    }

    /// <summary>
    /// 当前登录用户的角色ID
    /// </summary>
    protected decimal RoleID
    {
        get
        {
            if (Session["RoleID"] == null || string.IsNullOrEmpty(Session["RoleID"].ToString()))
            {
                return -1;
            }
            return Convert.ToDecimal(Session["RoleID"].ToString());
        }
    }

    /// <summary>
    /// 当前登录用户的名称
    /// </summary>
    protected string StaffName
    {
        get
        {
            return Session["StaffName"].ToString();
        }
    }

    /// <summary>
    /// 当前登录账号名称(惟一值)
    /// </summary>
    public string StaffLoginName
    {
        get
        {
            return Session["StaffLoginName"].ToString();
        }
    }



    protected List<string> GetCheckID(Grid Grid1)
    {
        List<string> li = new List<string>();
        int selectedCount = Grid1.SelectedRowIndexArray.Length;
        for (int i = 0; i < selectedCount; i++)
        {
            int rowIndex = Grid1.SelectedRowIndexArray[i];

            if (Grid1.AllowPaging && !Grid1.IsDatabasePaging)
            {
                rowIndex = Grid1.PageIndex * Grid1.PageSize + rowIndex;
            }
            string str = Grid1.DataKeys[rowIndex][0].ToString();
            li.Add(str);
        }
        return li;
    }


    public List<string> Competencelist
    {

        get
        {
            List<String> Li;
            Ylh.BLL.ComRoleBLL bll = new ComRoleBLL(DbConnectionStr);
            Li = bll.GetCompetenceByRoleID(RoleID.ToString());
            return Li;
        }
    }


}